 const {pinyin} = require('pinyin');	
class JQService {
	
    constructor(conn,req_obj,extra) {
		
        this.conn=conn;
		this.req_obj = req_obj;
		this.extra=extra; //url?extra
		
		
    }
	
	_extractInitials(str) {
	    let result = '';
	   
	 
	    for (let i = 0; i < str.length; i++) {
	        const char = str[i];
	        const code = str.charCodeAt(i);
	 
	        // 判断是否为汉字
	        if ((code >= 0x4e00 && code <= 0x9fff) || (code >= 0x3400 && code <= 0x4DBF) || (code >= 0x20000 && code <= 0x2A6DF) || (code >= 0x2A700 && code <= 0x2B73F) || (code >= 0x2B740 && code <= 0x2B81F) || (code >= 0x2B820 && code <= 0x2CEAF) || (code >= 0xF900 && code <= 0xFAFF)) {
	        
	                // 获取汉字拼音首字母
	                const pinyinArray = pinyin(char, { style: pinyin.STYLE_NORMAL })[0]; // 获取拼音数组，然后取第一个拼音的第一个字母
	                result += pinyinArray[0][0]; // 取拼音的首字母
	               
	         } else {
					result += char;
	                // 如果已经是汉字，则继续下一个循环
	               
	         }
	    } 
	    return result;
	}
	 
	_addParams(param,init_params, op){
		if(init_params){
			if(op)return [init_params,op,param];
			return [init_params,param];
		}
		return param;
	}
	
	
	_addUserParams(param){
		
		let params = this._addParams(['u_id=',this.req_obj.u_id],param);
		
		return params;
	}
	
	
	// _addBasicParams(){
		
	// 	let params = this._addParams(['u_id=',this.req_obj.u_id]);
	// 	if(this.req_obj.role!='admin'){
	// 		params= this._addParams(['b_id=',this.req_obj.visitor_id],params);
	// 	}
	// 	return params;
	// }
	
	
    do_action(){console.log('xxxxxx')};
	
	static  instance(subs,conn,req_obj,extra){
			try{
				console.log(`./services/${subs}  111`)
				const JQServiceI = require(`./services/${subs}`);
				console.log(`./services/${subs}`)
					
				if(JQServiceI){
					console.log('xxxxxxgg')
					let servicef = new JQServiceI(conn,req_obj,extra);
						console.log('xxxxxxgg222')
				
					return servicef;
				}
				
			}catch(e){
				console.log('service instance error::' + e.message);
				throw {'code':global.consts.Error.ERROR_OP,
					'message':global.consts.Message.UNKNOW_OP}
			    
			}
			return null;			
		
		}

}

module.exports = JQService;